﻿
using System;
using Red.Controls.TimeLine.Core;

namespace Red.Controls.TimeLine.ViewModels
{
    /// <summary>
    /// Base class for all ViewModels that can be placed on a TrackPanel
    /// </summary>
    public abstract class TrackItemBase : TimeLineItemBase
    {
        #region C-tor

        protected TrackItemBase( TimeLineId id, TimeLineControler controler )
            : base( id, controler )
        {
        }
      
        #endregion

        #region Properties

        public virtual double ActionTime
        {
            get { return DataModel?.GetValue<double>( "ActionTime" ) ?? 0.0; }
            set
            {
                double time = TimeLineControler.SnapTime( value );
                if ( DataModel != null )                    
                {
                    DataModel.SetValue<double>( "ActionTime", time );                    
                }
            }
        }

        #endregion

        #region Protected Methods

        protected override void OnDataModelChanged()
        {
            base.OnDataModelChanged();
            DataModel.RegisterProperty( "ActionTime", "startTime", OnActionTimeChanged );
        }

        protected virtual void OnActionTimeChanged( string propertyName, string value )
        {
            OnPropertyChanged( propertyName );
        }

        #endregion
    }
}

